{template header_common}
<link rel="stylesheet" type="text/css" href="/static/css/buy.css">
<div class="area buy">
	<div class="buy">
    	{if $addresslist}
    	<h3 class="h3-title">选择收货地址</h3>
    	<div class="address-div">
        	<ul id="addrlist">
            	{loop $addresslist $addr}
            	<li data-id="$addr[id]"{if $addr[isdefault]} class="cur"{/if}>
                	<h3>$addr[consignee]</h3>
                    <p>$addr[street]</p>
                    <p>$addr[province] $addr[city] $addr[county] $addr[postnum]</p>
                    <p>$addr[phone]</p>
                </li>
                {/loop}
            </ul>
        </div>
        <div class="blank"></div>
        {/if}
        <h3 class="h3-title">使用新收货地址</h3>
        <div>
        	<form method="post" id="addressForm" action="/?m=$G[m]&c=address&a=add">
            	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="address-form-table">
                  <tr>
                    <td class="item-name">省<i>*</i></td>
                    <td>
                    	<select id="province" name="addressnew[province]" style="width:auto;">
                          <option value="">请选择</option>
                        </select> 市:
                        <select id="city" name="addressnew[city]" style="width:auto;">
                            <option value="">请选择</option>
                        </select> 区:
                        <select id="county" name="addressnew[county]" style="width:auto;">
                            <option value="">请选择</option>
                        </select>
                    </td>
                  </tr>
                  <tr>
                    <td class="item-name">邮政编码<i>*</i></td>
                    <td><input type="text" name="addressnew[postnum]" class="input-text"></td>
                  </tr>
                  <tr>
                    <td class="item-name">街道地址<i>*</i></td>
                    <td><textarea class="w500" name="addressnew[street]"></textarea></td>
                  </tr>
                  <tr>
                    <td class="item-name">收货人姓名<i>*</i></td>
                    <td><input type="text" name="addressnew[consignee]" class="input-text"></td>
                  </tr>
                  <tr>
                    <td class="item-name">手机号码<i>*</i></td>
                    <td><input type="text" name="addressnew[phone]" class="input-text"></td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td><button class="button" type="button" id="addaddress">确认地址</button></td>
                  </tr>
                </table>
            </form>
        </div>
        <form method="post" id="orderForm" action="/?m=$G[m]&c=order">
        <input type="hidden" name="addressid" value="0" id="addressid">
        <input type="hidden" name="goods_id" value="$id">
        <input type="hidden" name="goods_number" value="$goods_number">
        <input type="hidden" name="goods_price" value="$goods_price">
        <input type="hidden" name="total_amount" value="$total_amount">
        <table cellpadding="0" cellspacing="0" width="100%" class="goods-table">
        	<thead>
            	<tr>
                	<th>商品</th>
                    <th width="120">商品信息</th>
                    <th width="100">价格</th>
                    <th width="60">数量</th>
                    <th width="100">小计</th>
                </tr>
            </thead>
            <tbody>
            	<tr>
                	<td>
                    	<div class="pic"><a href="/?m=goods&c=detail&id=$id" target="_blank">
                        <img src="{echo image($goods[image])}"></a></div>
                        <div class="name"><a href="/?m=goods&c=detail&id=$id" target="_blank">$goods[name]</a></div>
                    </td>
                    <td>红色</td>
                    <td class="amount">￥{echo @number_format($goods_price, 2)}</td>
                    <td>{$goods_number}</td>
                    <td class="amount">￥{echo @number_format($total_amount, 2)}</td>
                </tr>
            </tbody>
        </table>
        </form>
        <!--结算-->
        <div class="settlement-div">
        	<a class="settlement" id="settlement">结算</a>
            <div class="total-amount">总计: <span>￥{echo @number_format($total_amount, 2)}</span></div>
            <div class="num">共选择了{$goods_number}件商品</div>
        </div>
    </div>
</div>
<script type="text/javascript">
DSXCMS.showDistrict(0, '#province', '$profile[province]', '选择省份');
$("#province").change(function(e) {
	var fid = parseInt($(this).find(":selected").attr("idvalue"));
    if(fid) DSXCMS.showDistrict(fid, '#city', '$profile[city]', '选择城市');
});
$("#city").change(function(e) {
	var fid = parseInt($(this).find(":selected").attr("idvalue"));
    if(fid) DSXCMS.showDistrict(fid, '#county', '$profile[county]', '选择区县');
});
$("#addaddress").click(function(e) {
    $("#addressForm").ajaxSubmit({
		dataType:'json',
		success:function(json){
			if(json.errno == 0){
				window.location = window.location.href;
			}else {
			}
		}
	});
});
$("#addrlist li").click(function(e) {
    $(this).addClass('cur').siblings().removeClass();
	$("#addressid").val($(this).attr("data-id"));
});
$("#settlement").click(function(e) {
    var addrid = parseInt($("#addressid").val());
	if(!addrid) {
		alert('请选择一个收获地址');
		return false;
	}else {
		$("#orderForm").submit();
	}
});
</script>
{template footer_common}